/***************************************************************************
 *   Copyright (C) 2009 by Dead_Body                                       *
 *   jamesholodnak@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "defines.h"
#include "pce/pce.h"

static u8 reg;

void pce_vce_reset()
{

}

u8 pce_vce_read(u32 address)
{
	u8 ret = 0;

	switch(address & 3) {
		case 0:
			return(ret);

		case 2:
			return(ret);

		case 3:
			return(ret);
	}
	return(0);
}

void pce_vce_write(u32 address,u8 data)
{
	u16 color;
	u8 r,g,b;
	switch(address & 3) {
		case 0:
			pce->vce.cr &= 0xFF00;
			pce->vce.cr |= data;
			break;
		case 2:
			pce->vce.coloridx &= 0xFF00;
			pce->vce.coloridx |= data;
			break;
		case 3:
			pce->vce.coloridx &= 0x00FF;
			pce->vce.coloridx |= data << 8;
			break;
		case 4:
			pce->vce.colors[pce->vce.coloridx] &= 0xFF00;
			pce->vce.colors[pce->vce.coloridx] |= data;
			color = pce->vce.colors[pce->vce.coloridx];
			r = ((color >> 3) & 7) << 5;
			g = ((color >> 6) & 7) << 5;
			b = ((color >> 0) & 7) << 5;
			video_setpalentry(pce->vce.coloridx,r,g,b);
			break;
		case 5:
			pce->vce.colors[pce->vce.coloridx] &= 0x00FF;
			pce->vce.colors[pce->vce.coloridx] |= data << 8;
			color = pce->vce.colors[pce->vce.coloridx];
			r = ((color >> 3) & 7) << 5;
			g = ((color >> 6) & 7) << 5;
			b = ((color >> 0) & 7) << 5;
			video_setpalentry(pce->vce.coloridx,r,g,b);
			log_message("setting palette entry %d to $%02X $%02X $%02X\n",pce->vce.coloridx,r,g,b);
			break;
	}
}
